/*
   metric\log2world\worldsim 页的添加到组功能（打开弹窗、关闭弹窗、提交）
*/
import { appendMetricInGroup } from '@/api/metric'
import {appendCaseInGroup } from '@/api/case'
export default function addToGroupMixin(tag) {
  return {
    methods: {
      // 添加到分组 打开弹窗
      _handleAddToGroup() {
        this.getCustomGroup()
        this.isVisibleAppendGroupModal = true
      },
      // 关闭弹窗
      _closeAppendDialog() {
        this.isVisibleAppendGroupModal = false
        switch (tag){
          case 'metric':
            this.$refs.metricTable.$refs.myTable.clearSelection()
            break
          case 'worldsim':
            this.$refs.worldsimTable.$refs.myTable.clearSelection()
            break
          case 'log2world':
            this.$refs.log2worldTable.$refs.myTable.clearSelection()
            break
          default:
            break
        }
      },
      // 提交 
      _submitAppend(group_id) {
        switch (tag){
          case 'metric':
            const metricParams = {
              group_id,
              metric_id: this.selectedMetrics
            }
            // 将metric加入到自定义组内，发送给后端
            appendMetricInGroup(metricParams).then(res => {
              this.$message.success('添加到组成功！')
            })
            this.$refs.metricTable.$refs.myTable.clearSelection()
            break
            case 'worldsim':
              const worldsimParams = {
                group_id,
                case_id: this.selectIds
              }
              // 将case加入到自定义组内，发送给后端
              appendCaseInGroup(worldsimParams).then(res => {
                  this.$message.success('添加到组成功！')
              })
              this.$refs.worldsimTable.$refs.myTable.clearSelection()
              break
            case 'log2world':
              const log2worldParams = {
                group_id,
                case_id: this.selectedRecords
              }
              // 将case加入到自定义组内，发送给后端
              appendCaseInGroup(log2worldParams).then(res => {
                  this.$message.success('添加到组成功！')
              })
              this.$refs.log2worldTable.$refs.myTable.clearSelection()
              break
          default :
            break
        }
        this.isVisibleAppendGroupModal = false
      },
    }
  }
}